/*************************************
ScreenGameplay.h
Created By VietRise on 4/6/2014

*************************************/

#ifndef __SCREENGAMEPLAY_H__
#define __SCREENGAMEPLAY_H__

#include "cocos2d.h"
#include <iostream>
#include "SimpleAudioEngine.h"
#include "Circle.h"
#include "Sprites\Bomb.h"
#include "Sprites\Diamond.h"
#include "Sprites\Hammer.h"
#include "Sprites\Hole.h"
#include "Sprites\Mouse.h"
#include "Sprites\OldMan.h"

USING_NS_CC;
using namespace CocosDenshion;
using namespace std;

class ScreenGameplay : public cocos2d::CCLayer
{
private:
	static ScreenGameplay* _instance;

	CCSpriteBatchNode* _gameBatchNode;
	CCSize _screenSize;

	CCSprite* _boardTarget;
	CCSprite* _boardPause;
	CCSprite* _boardResult;
	CCSprite* _boardMouse;
	CCSprite* _boardCombo;
	CCSprite* _boardDiamond;

	CCSprite* _btnStart;
	CCSprite* _btnBack;
	CCSprite* _btnPause;
	CCSprite* _btnMenu;
	CCSprite* _btnNext;
	CCSprite* _btnReplay;
	CCSprite* _btnResume;			

	Hammer* _hammer;
	CCArray* _buttons;
	CCArray* _levelPool;
	CCArray* _bombPool;
	CCArray* _diamondPool;
	CCArray* _holePool;
	CCArray* _mousePool;
	CCArray* _oldManPool;

	// Data on each level
	int _numberMouseTarget;
	int _numberComboTarget;
	int _numberDiamondTarget;

	int _numberMouseAppearance;
	int _numberMouseOnScreen;
	float _durationMouseDelay[2];
	float _durationMouseAppearance[2];

	int _numberOldManAppearance;
	int _numberOldManOnScreen;
	float _durationOldManDelay[2];
	float _durationOldManAppearance[2];

	int _numberDiamondOnScreen;
	float _durationDiamondDelay[2];
	float _durationDiamondAppearance[2];

	int _numberBombOnScreen;
	float _durationBombDelay[2];
	float _durationBombAppearance[2];

	

	// Members data in game	
	int _level;

	int _numberMouseTargetInGame;
	int _numberComboTargetInGame;
	int _numberDiamondTargetInGame;
	int _countMouseHit;
	int _countMouseMiss;
	int _countOldManHit;
	int _countOldManAppear;
	int _countDiamondHit;
	int _countCombo;
	int _countCurrentCombo;

	bool _noHitBomb;

	// Methods
	void createScreen();
	void createPools();
	void createActions();	

	void checkCollision();

public:
	CC_SYNTHESIZE(int, _levelCompleted, LevelCompleted);
	CC_SYNTHESIZE(STATEGAMEPLAY, _state, State);
	~ScreenGameplay();
	ScreenGameplay();

	static CCScene* scene(int level, int levelCompleted);
	static ScreenGameplay* create(int level, int levelCompleted);

	void update(float dt);

	void loadLevel(int level);
	void resetLevel();
	void clearLayer(bool resetGame);
	void pauseGame();
	void loseGame();
	void winGame();

	virtual void ccTouchesBegan(CCSet* pTouches, CCEvent* event);
	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesEnded(CCSet* pTouches, CCEvent* event);

	void setHoleBlank(int hole);
	void increaseMouseMiss();
	void increaseMouseHit();
	void hideLabelCombo(CCNode* pSender);
};

#endif // __SCREENGAMEPLAY_H__
